<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/common::common_header(~{::title},~{})">

    <title>学生选课情况查询</title>


</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <div th:replace="~{common/common::sidebar(first='info',second='result')}"></div>
        <!--End 左侧导航-->

        <!--头部信息-->
        <div th:replace="~{common/common::topbar}"></div>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h3>选课情况查询</h3>
                                <div class="pull-right">
                                    <button class="btn btn-label btn-w-lg btn-primary" id="noChoose">
                                        <label><i class="mdi mdi-checkbox-marked-circle-outline"></i></label> 确认退课
                                    </button>
                                </div>
                            </div>

                            <div class="card-body">

                                <div class="table-responsive">
                                    <table class="table table-hover">
                                        <!-- 表头 -->
                                        <thead>
                                        <tr>
                                            <th scope="col">序号</th>
                                            <th scope="col">课程号</th>
                                            <th scope="col">课程名</th>
                                            <th scope="col">教师
                                            <th>
                                            <th scope="col">学分</th>
                                            <th scope="col">学时</th>
                                            <th scope="col">上课时间</th>
                                            <th scope="col">上课地点</th>
                                            <th scope="col">课程性质</th>
                                            <th scope="col">开课学院</th>
                                            <th scope="col">退选</th>
                                        </tr>
                                        </thead>
                                        <!-- 表格内容 -->
                                        <tbody id="tbody">
                                        <tr th:each="result:${Result.list}">
                                            <th scope="row" th:text="${resultStat.index+1+Result.size*Result.number}"></th>
                                            <td th:text="${result.planEntity.cno}"></td>
                                            <td th:text="${result.planEntity.cname}"></td>
                                            <td th:text="${result.planEntity.cteacher}"></td>
                                            <td th:text="${result.planEntity.credit}"></td>
                                            <td th:text="${result.planEntity.xueshi}"></td>
                                            <td th:text="${result.planEntity.studytime}"></td>
                                            <td th:text="${result.planEntity.studylocation}"></td>
                                            <td th:text="${result.planEntity.cnature}"></td>
                                            <td th:text="${result.planEntity.college}"></td>
                                            <td><input type="checkbox" name="noChoose" th:value="${result.pno}"></td>
                                        </tr>
                                        </tbody>

                                    </table>
                                </div>

                                <div>
                                    <ul class="pagination pull-right">
                                        <li><a th:href="@{'/result/list?pageNum=0'}">首页</a></li>
                                        <li>
                                            <a th:if="${Result.number!=0}" th:href="@{'/result/list?pageNum=' + ${Result.number - 1}}" >上一页</a>
                                        </li>
                                        <li>
                                            <a th:if="${Result.number==0}" th:href="@{'/result/list?pageNum=0'}" >上一页</a>
                                        </li>

                                        <!--<li th:each="pageNum:${#numbers.sequence(0, Plan.getTotalPages() - 1)}">
                                            <a th:href="'/choose/list?pageNum=' + ${pageNum}" th:text="${pageNum + 1}" th:if="${pageNum ne Plan.pageable.getPageNumber()}"></a>
                                            <a th:href="'/choose/list?pageNum=' + ${pageNum}" th:text="${pageNum + 1}" th:if="${pageNum eq Plan.pageable.getPageNumber()}" th:style="'font-weight:bold;background: #6faed9;'"></a>
                                        </li>
                                        <li><a class="btn btn-default btn-lg active" href="#" >1</a></li>-->

                                        <li>
                                            <a th:if="${Result.number != (Result.totalPages-1)}" th:href="@{'/result/list?pageNum=' + ${Result.number + 1}}" >下一页</a>
                                        </li>
                                        <li>
                                            <a th:if="${Result.number == (Result.totalPages-1)}" th:href="@{'/result/list?pageNum=' + ${Result.totalPages - 1}}" >下一页</a>
                                        </li>
                                        <li><a th:href="@{'/result/list?pageNum='+ ${Result.totalPages==0? 0:Result.totalPages-1} }" >尾页</a></li>
                                    </ul>
                                </div>
                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<div th:replace="common/common::common_js(~{::script})">
    <script>

        function getPno() {
            var pno = "";
            $.each($('input:checkbox:checked'), function () {
                pno = $(this).val();
                return false;
            });
            return pno;
        }

        $('#noChoose').click(function () {
            if (confirm("再次确认是否要真的退选,请谨慎考虑！")) {
                $.ajax({
                    url: "/result/" + getPno() + "/noChoose",
                    type: "POST",
                    /*data: {
                        pno: getPno(),
                    },*/
                    success: function (dto) {

                        if(dto.success){
                            alert(dto.data);
                            //重新加载页面
                            location.href = "/result/list?pageNum=0";
                        }else{
                            alert(dto.errMsg);
                        }
                    },
                    error: function () {
                        alert("执行错误");
                    }
                });
            } else {

            }


        });
    </script>
</div>

</body>
</html>